package com.horsecoder.im.common.protocol.action.handler;

import com.horsecoder.im.common.protocol.context.chain.request.Request;
import com.horsecoder.im.common.protocol.context.chain.response.Response;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Author: Zhu yuhan
 * Email: zhuyuhan2333@qq.com
 * Date: 2022/3/16 1:27 下午
 **/
public abstract class ProxyActionHandler implements Handler {

    private static final Logger LOGGER = LoggerFactory.getLogger(ProxyActionHandler.class);

    @Override
    public void handle(Channel channel, Request request, Response response) {
        ChannelFuture channelFuture = handle0(channel, request, response);
        String identity = request.getIdentity();
        String receiver = request.getReceiver();
        String message = request.getMessage();
        channelFuture.addListener((f) -> {
            LOGGER.info("attempt to transfer msg from:{} to:{} with content:{}",
                    identity, receiver, message);
        });
    }

    public abstract ChannelFuture handle0(Channel channel, Request request, Response response);
}
